;*****************************************************************************************************
;+
; NAME:
;
;      eCOLORBAR (enhanced COLORBAR)
;
; PURPOSE:
;
;      This routine draws a color bar on the current IGL window. The
;      color bar will be drawn with the current colors loaded in the color
;      table of the window.
;
; CALLING SEQUENCE:
;
;      eCOLORBAR
;
; ARGUMENTS:
;
;     None.
;                 
; KEYWORD PARAMETERS:
;
;     CHARSIZE:      The character size of the color bar
;                    annotations. The default is !IGL_P.charsize
;
;     COLOR:         The name of the color to use for drawing the borders and annotations
;                    of the colorbar. The default is !IGL_P.color
;
;     DIVISIONS:     The number of divisions to divide the bar into. There will
;                    be (divisions + 1) annotations. The default is 6.
;
;     FONT:          Sets the font of the annotation.
;                    -1 : Herschey, 0 : Hardware, 1 : True Type.
;                    The default is !IGL_P.font
;
;     FORMAT:        The format of the bar annotations. Default is '(I5)'.
;
;     INVERTCOLORS:  Setting this keyword inverts the colors in the color bar.
;
;     MINOR:         The number of minor tick divisions. Default is 2.
;
;     NCOLORS:       This is the number of colors in the color bar.
;
;     NOINTERP:      Normally the colors are interpolated in the color
;                    bar. Setting this keyword will ensure the colors
;                    are replicated by nearest neighbor sampling.
;
;     POSITION:      A four-element array of normalized coordinates in the same
;                    form as the POSITION keyword on a plot. Default is
;                    [0.88, 0.10, 0.95, 0.90] for a vertical bar and
;                    [0.10, 0.88, 0.90, 0.95] for a horizontal bar.
;
;     RANGE:         A two-element vector of the form [min, max]. The
;                    default is [0,255].
;
;     RIGHT:         This puts the labels on the right-hand side of a vertical
;                    color bar. It applies only to vertical color bars.
;
;     THICKNESS:     Set this to the thickness of the line around the
;                    colorbar. The default is !IGL_P.thick
;
;     TICKNAMES:     A string array of names or values for the tick marks.
;
;     TITLE:         A string used as the title of the colorbar. Set to "" by default.
;
;     TOP:           This puts the labels on top of the bar rather than under it.
;                    The keyword only applies if a horizontal color bar is rendered.
;
;     VERTICAL:      Setting this keyword give a vertical color bar. The default
;                    is a horizontal color bar.
;
;     NODRAW:        Set this keyword to prevent the
;                    current window to be refreshed. The color bar
;                    is added to the window but will not be
;                    visible until the window is refreshed (by calling
;                    another IGL plotting command for example). This is
;                    useful is you wish to issue several plotting
;                    commands but want to display the results only at
;                    the end.
;    
; PACKAGE:
;
;    Interactive Graphics Library (IGL)
;
; AUTHORS:
;
;        RAPHAEL SADOUN
;        Graduate Student
;        Institut d'Astrophysique de Paris
;        98 bis boulevard Arago
;        75014 PARIS FRANCE
;        E-mail: raphael.sadoun@gmail.com
;
;
; MODIFICATION HISTORY:
;
;     Written by: Raphael Sadoun, 24 April 2012
;-
;*****************************************************************************************************
PRO eCOLORBAR, CHARSIZE=charsize, $
               COLOR=color, $
               DIVISIONS=divisions, $
               FONT=font, $
               FORMAT=format, $
               INVERTCOLORS=invertcolors, $
               MINOR=minor, $
               NCOLORS=ncolors, $
               NOINTERP=nointerp, $
               POSITION=position, $
               RANGE=range, $
               RIGHT=right, $
               THICKNESS=thickness, $
               TICKLEN=ticklen, $
               TICKNAMES=ticknames, $
               TITLE=title, $
               TOP=top, $
               VERTICAL=vertical, $
               NODRAW=nodraw

  COMPILE_OPT idl2, HIDDEN
  ON_ERROR, 2

  ;; Initialize the global system variables
  IGL_InitSysVars

  ;; Default keyword values
  IF N_Elements(charsize) EQ 0 THEN charsize = (!IGL_P.charsize LE 0) ? 1 : !IGL_P.charsize
  IF N_Elements(color) EQ 0 THEN color = !IGL_P.color
  IF N_Elements(thick) EQ 0 THEN thick = (!IGL_P.thick LE 0) ? 1 : !IGL_P.thick
  IF N_Elements(font) EQ 0 THEN font = !IGL_P.font

  ;; Get current window
  currentWindow = IGL_GetCurrentWindow()
  IF OBJ_ISA_VALID(currentWindow,'IGL_Window') EQ 0 THEN Message,'No valid IGL window available'

  ;; Create the colorbar object
  colorBar = obj_new('IGL_ColorBar', $
                     CHARSIZE=charsize, $
                     COLOR=color, $
                     DIVISIONS=divisons, $
                     FORMAT=format, $
                     INVERTCOLORS=Keyword_Set(invertcolors), $
                     MINOR=minor, $
                     NCOLORS=ncolors, $
                     NOINTERP=Keyword_Set(nointerp), $
                     POSITION=position, $
                     RANGE=range, $
                     RIGHT=Keyword_Set(right), $
                     TICKLEN=ticklen, $
                     TICKNAMES=ticknames, $
                     TITLE=title, $
                     TOP=top, $
                     VERTICAL=Keyword_Set(vertical), $
                     FONT=font, $
                     THICKNESS=thick $
                    )

  ;; Add it to the window
  currentWindow -> AddGraphic, colorBar

  ;; Refresh property editor
  currentWindow -> GetProperty, PropertyPanel=PropertyPanel
  IF OBJ_VALID(PropertyPanel) THEN PropertyPanel -> UpdateTreeBrowser
  
  ;; Draw window's content
  IF Keyword_Set(nodraw) EQ 0 THEN currentWindow -> DrawWindow, /BUFFERED_OUTPUT

END
